package john.wenzi.server;

import java.net.InetSocketAddress;
import java.util.EnumSet;

import javax.servlet.DispatcherType;
import javax.xml.ws.Dispatch;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;

import john.wenzi.server.filter.PermissionCheckFilter;
import john.wenzi.server.servlet.DownloadServlet;
import john.wenzi.server.servlet.FindAllFileServlet;
import john.wenzi.server.servlet.FindFileServlet;
import john.wenzi.server.servlet.UploadServlet;

public class ServerApp {
	    private final static String HOST = "127.0.0.1";
	    private final static String PORT = "9000";
	    public static void main(String[] args) throws Exception {
	        InetSocketAddress address = new InetSocketAddress(HOST , Integer.parseInt(PORT));
	        //新建web服务器
	        Server server = new Server(address);
	        //添加自定义的Servlet
	        ServletContextHandler handler = new ServletContextHandler();
	        //权限校验过滤器
	        handler.addFilter(PermissionCheckFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
	        //上传文件servlet
	        handler.addServlet(UploadServlet.class , "/uploadfile");
	        //下载文件servlet
	        handler.addServlet(DownloadServlet.class , "/downloadfile");
	        //查询历史信息servlet
	        handler.addServlet(FindAllFileServlet.class , "/findallfile");
	        //查询上传信息servlet
	        handler.addServlet(FindFileServlet.class , "/findfile");
	        server.setHandler(handler);
	        //启动web服务器
	        server.start();
	    }
}
